package com.ysd.lis.service.inv.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.inv.InvSupplierAppraise;
import com.ysd.lis.mapper.inv.InvSupplierAppraiseMapper;
import com.ysd.lis.request.inv.InvSupplierAppraiseDto;
import com.ysd.lis.request.inv.InvSupplierAppraiseParam;
import com.ysd.lis.service.inv.InvSupplierAppraiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author prs
 * @since 2024-09-10
 */
@Service
public class InvSupplierAppraiseServiceImpl extends ServiceImpl<InvSupplierAppraiseMapper, InvSupplierAppraise> implements InvSupplierAppraiseService {
    @Autowired
    InvSupplierAppraiseMapper invSupplierAppraiseMapper;

    @Override
    public Result findInvSupplierAppraiseList(InvSupplierAppraiseParam param) {
        MPJLambdaWrapper<InvSupplierAppraise> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(InvSupplierAppraise.class);
        if (StringUtils.isNotBlank(param.getSupplierId())) {
            queryWrapper.eq(InvSupplierAppraise::getSupplierId,param.getSupplierId());
        }

        queryWrapper.eq(InvSupplierAppraise::getDelFlag, 0)
                .orderByAsc(InvSupplierAppraise::getSeq);
        return Result.succ(1, "查询成功", invSupplierAppraiseMapper.selectList(queryWrapper));
    }

    @Override
    public Result saveOrUpdateInvSupplierAppraise(InvSupplierAppraiseDto dto) {
        List<InvSupplierAppraise> appraiseList = dto.getAppraiseList();
        boolean b = this.saveOrUpdateBatch(appraiseList);
        if(b){
            return Result.succ(1, "成功", null);
        }else {
            return Result.fail(400,"失败","");
        }
    }
    @Override
    public Result batchDeleteInvSupplierAppraiseList(InvSupplierAppraiseDto dto) {
        List<InvSupplierAppraise> appraiseList = dto.getAppraiseList();
        List<String> ids = appraiseList.stream().map(InvSupplierAppraise::getId).collect(Collectors.toList());
        boolean b = this.removeByIds(ids);
        if(b){
            return Result.succ(1, "删除成功", null);
        }else {
            return Result.fail(400,"删除失败","");
        }
    }
}
